package liumengbaio.lolzhangyoubao.Activity.Fragment;

import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.TextView;

import liumengbaio.lolzhangyoubao.R;

/**
 * 周免/折扣
 * Created by lanouhn on 16/8/23.
 */
public class FragmentHeroWeekFreeOrDiscount extends Fragment {

    private TextView topLefttv;
    private TextView topRighttv;
    private LinearLayout ll_hero_weekfreeordiscount;
    private FragmentHeroWeekFree one;
    private FragmentHeroDiscount two;
    private FragmentManager fm = getFragmentManager();
    private FrameLayout frameLayout;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {


        View view = inflater.inflate(R.layout.fragment_weekfreeordiscount, null);

        return view;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        initView(getView());
        initData();
        initEvent();


    }


    private void initView(View view) {

        frameLayout = (FrameLayout) view.findViewById(R.id.week_framlayout);
        topLefttv = (TextView) view.findViewById(R.id.topLefttv);
        topRighttv = (TextView) view.findViewById(R.id.topRighttv);
        ll_hero_weekfreeordiscount = (LinearLayout) view.findViewById(R.id.ll_hero_weekfreeordiscount);
        one = new FragmentHeroWeekFree();
        two = new FragmentHeroDiscount();
        FragmentTransaction transaction = getFragmentManager().beginTransaction();
        transaction.add(R.id.week_framlayout, one);
        transaction.add(R.id.week_framlayout, two);
        transaction.hide(two);
        transaction.commit();
    }

    private void initData() {

    }

    private void initEvent() {
        topLefttv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                topLefttv.setTextColor(Color.WHITE);
                topRighttv.setTextColor(Color.BLACK);
                ll_hero_weekfreeordiscount.setBackgroundResource(R.drawable.free_pressed_);
                FragmentTransaction left_transaction = getFragmentManager().beginTransaction();
                left_transaction.hide(two);
                left_transaction.show(one);
                left_transaction.commit();

            }
        });

        topRighttv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                topLefttv.setTextColor(Color.BLACK);
                topRighttv.setTextColor(Color.WHITE);
                ll_hero_weekfreeordiscount.setBackgroundResource(R.drawable.discount_pressed_);
                FragmentTransaction right_transaction = getFragmentManager().beginTransaction();
                right_transaction.hide(one);
                right_transaction.show(two);
                right_transaction.commit();
            }
        });

    }
}
